package com.xxl.job.kettle.exception;

import com.xxl.job.kettle.enums.GlobalStatusEnum;
import com.xxl.job.kettle.enums.base.BaseEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.text.MessageFormat;

/**
 * 实现功能：
 *
 * @author 作者[zk]
 * @version 1.0.00  2022-11-25 16:25
 */
@EqualsAndHashCode(callSuper = false)
@Data
public class ExecutorException extends RuntimeException {
    private String errorCode;
    private String errorMsg;

    public ExecutorException() {
    }

    public ExecutorException(String errorMsg) {
        this(GlobalStatusEnum.FAIL, errorMsg);
    }

    public ExecutorException(BaseEnum errorEnum, String errorMsg) {
        super(MessageFormat.format("errorCode:{0}, errorMsg:{1}---->{2}", errorEnum.getCode(), errorEnum.getDesc(), errorMsg));
        this.errorCode = errorEnum.getCode().toString();
        this.errorMsg = errorMsg;
    }

    public ExecutorException(String errorCode, String errorMsg) {
        super(MessageFormat.format("errorCode:{0}, errorMsg:{1}", errorCode, errorMsg));
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    public ExecutorException(String errorCode, String errorMsg, Throwable cause) {
        super(MessageFormat.format("errorCode:{0}, errorMsg:{1}", errorCode, errorMsg), cause);
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }
}
